import Vue from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
import { directivesExt } from '@/lib/directives.js';
import ShowHide from '@/utils/showhide';

import '@/utils/HxmTable/HxmTable.js';
import '@/utils/HxmTable/hxmTable.less';

import '@/icons';
import { initTheme } from '@atom/b2c-tokens';
import '@atom/b2c-tokens/dist/variables.css';
import {
  Clamp,
  Empty,
  Tabs,
  Tab,
  Button,
  Loading,
  Calendar,
  CalendarTab,
  Popup,
  Picker,
  BottomSheet,
  Cell,
  CellGroup,
  Checkbox,
  CheckboxGroup,
  Icon,
  Sticky,
  Overlay,
  RadioGroup,
  Radio,
} from '@atom/atom-ui';

initTheme();
// 重写onShow，onHide的监听事件
Vue.use(ShowHide);
Vue.use(Clamp);
Vue.use(Empty);
Vue.use(Tabs);
Vue.use(Tab);
Vue.use(Button);
Vue.use(Loading);
Vue.use(Calendar);
Vue.use(CalendarTab);
Vue.use(Popup);
Vue.use(Picker);
Vue.use(BottomSheet);
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Icon);
Vue.use(Sticky);
Vue.use(Overlay);
Vue.use(RadioGroup);
Vue.use(Radio);

Vue.use(window.hxmui, {
  componentsConfig: {
    PickerWheel: {
      BScroll,
    },
  },
});

// 注册全局组件
Vue.use(window.hxmui, { projectName: 'advancedStockPool' });
Vue.use(window._Components.StockList);
Vue.use(window._Components.StockListItem);

Vue.use(window.subscribeMobile);

// 添加全局指令
Vue.directive('hxm-redgreen', {
  bind(el, binding) {
    setTimeout(() => {
      directivesExt.redgreenhandler(el, binding);
    }, 30);
  },
  componentUpdated(el, binding) {
    setTimeout(() => {
      directivesExt.redgreenhandlerUpdate(el, binding);
    }, 50);
  },
});
const FOUR = 40;
const FIVE = 50;
Vue.directive('hxm-fontResize', {
  bind(el, binding) {
    setTimeout(() => {
      directivesExt.fontresizehandler(el, binding);
    }, FOUR);
  },
  componentUpdated(el, binding) {
    setTimeout(() => {
      directivesExt.fontresizehandler(el, binding);
    }, FIVE);
  },
});
Vue.config.productionTip = false;

Vue.config.errorHandler = error => {
  window.console.error(error);
  window.ClientMonitor.reportFrameErrors(
    {
      category: 'js', // 类型
      grade: 'Warning', // 级别
    },
    error
  );
};
new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app');
